<?php
namespace app\manager\controller;

class CampType extends BaseController
{
    /**
     * GET shwo camptype info list
     * @return [type] [description]
     */
    public function index()
    {
        $list = model('CampTypes')->getCampTypeLists();//halt($list);
        $this->assign('list',$list);
        $id = session('manager.id');
        $this->assign('id',$id);
        return view('p/camptype/index');
    }
    
    /**
     * GET shwo create camptype info
     * @return [type] [description]
     */
    public function branch()
    {
        return view('p/camptype/branch');
    }

    /**
     * GET show camptype info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function read($id)
    {

    }

    /**
     * GET shwo create camptype info
     * @return [type] [description]
     */
    public function create()
    {
        
        return view('p/camptype/create');
    }

    /**
     * POST create new camptype info
     * @return [type] [description]
     */
    public function save()
    {
        $post_camptype_info['name'] = input('post.name');
        $post_camptype_info['profiles'] = input('post.profiles');

        $camptype = model('CampTypes')->createCampType($post_camptype_info);        

        if($camptype){
            return $this->success('创建成功','/camptype');
        }
            return $this->error('创建失败');
    }

    /**
     * GET edit camptype info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function edit($id)
    {
        $data = model('CampTypes')->getCampTypeInfo($id);
        $this->assign('data',$data);
        $this->assign('id',$id);
        return view('p/camptype/edit');
    }

    /**
     * PUT update camptype info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function update($id)
    {
        $post_camptype_info['name'] = input('post.name');
        $post_camptype_info['profiles'] = input('post.profiles');
        
        $camptype = model('CampTypes')->updateCampType($id, $post_camptype_info);

        if($camptype){
        	return $this->success('更新成功','/camptype');
        }
        	return $this->error('更新失败');
    }

    /**
     * DELETE camptype info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete($id)
    {
       $ids=input('post.ids/a');
        if (empty($ids)) {
          return $this->error('请选择要删除的选项'); 
        }
        $count = model('CampTypes')->delInfo($ids);
        if ($count) {
           return $this->success('删除成功','/camptype');
        }
        return $this->error('删除失败');
    }
    
    

}

